/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.core.enums;

import java.util.ArrayList;
import java.util.List;


public final class CourseType extends AbstractEnumType {
	
	private static List<CourseType> types = new ArrayList<CourseType>(); 

	public CourseType()
	{
	}
	
	private CourseType(final String name, final String abbreviation)
	{
		super(name, abbreviation);
	}
	
	public static void reset()
	{
		types.clear();
	}
	
	public static void addCourseType(final String name, final String abbreviation)
	{
		types.add(new CourseType(name, abbreviation));
	}
	
	public int ordinal() {
		return types.indexOf(this);
	}

	public static CourseType[] values() {
		final CourseType[] result = new CourseType[types.size()];
		for (int i = 0; i < result.length; i++) {
			result[i] = types.get(i);
		}
		return result;
	}

	public static CourseType valueOf(final String type) {
		for (CourseType rt : types) {
			if (type.equals(rt.getAbbreviation())) {
				return rt;
			}
			if (type.equals(rt.getAbbreviation() + " - " + rt.getName())) {
				return rt;
			}
		}

		return null;
	}
	
	public static List<CourseType> setOf(final CourseType ... types)
	{
		final List<CourseType> result = new ArrayList<CourseType>();
		for (final CourseType type : types) {
			result.add(type);
		}
		return result;
	}
}
